using System;
using System.Collections.Generic;
using System.Text;
using GarageGames.Torque.T2D;
using Xyne.Utilities;
using GarageGames.Torque.Core;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Net;
using Xyne.Actions;

namespace Xyne.Templates.BattleEffects
{
    public class SplatterEffect : BattleEffect
    {
        private const string ObjectName = "Splatter";

        #region Template
        private static SplatterEffect _template;

        public static SplatterEffect Template
        {
            get
            {
                if (_template == null)
                {
                    _template = new SplatterEffect();
                }

                return _template;
            }
        }
        #endregion

        #region Constructor
        public SplatterEffect()
        {
            IsTemplate = true;
            Name = ObjectName;

            CreateWithWorldLimit = true;
            AnimationData = AnimationManager.Instance.GetAnimationData("explodeANIM");
            Layer = Game.EffectLevel;
            ObjectType = TorqueObjectDatabase.Instance.GetObjectType(Name);

            Size = new Vector2(25, 25);
            EffectType = BattleEffect.BattleEffectType.SplatterEffect;
        }
        #endregion

        #region Init
        public void Init(DirectHealthAction directHealthAction)
        {
            Size = Size * ((float)directHealthAction.Level) / 1.5f;
        }
        #endregion

        public void Update(PacketReader reader)
        {
            WarpToPosition(reader.ReadVector2(), 0);
            Size = reader.ReadVector2();
        }

        #region Overrides
        public override void StartEffect()
        {
            base.StartEffect();
            OnAnimationEnd = new OnAnimationEndDelegate(AnimationEnded);
        }

        public override void Serialize(PacketWriter writer)
        {
            writer.Write(Position);
            writer.Write(Size);
        }
        #endregion

        #region Events
        public void AnimationEnded()
        {
            BattleEffectManager.Instance.RemoveBattleEffect(this);
            MarkForDelete = true;
        }
        #endregion
    }
}
